package Fenetre;

import java.awt.GridLayout;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.Clause.Biais.*;

public class PanelBiais extends JPanel{
	private static final long serialVersionUID = 2612153744965628218L;
	
	private JLabel label_clause_de_horn;
	private JLabel label_range_restricted;
	private JLabel label_nb_literaux_corps;
	private JLabel label_nb_variables_existentielles;
	
	private JPanel panel_labels;

	private JCheckBox check_clause_de_horn;
	private JCheckBox check_range_restricted;
	private JCheckBox check_nb_literaux_corps;
	private JCheckBox check_nb_variables_existentielles;
	
	private JPanel panel_checks;

	private JSpinner spin_nb_literaux_corps;
	private JSpinner spin_nb_variables_existentielles;
	
	private JPanel panel_spins;

	public PanelBiais(){
		super();
		ajouterObjetsGraphiques();
		ajouterListeners();
	}

	private void ajouterObjetsGraphiques(){
		label_clause_de_horn = new JLabel("Clause de Horn");
		label_range_restricted = new JLabel("Range Restricted");
		label_nb_literaux_corps = new JLabel("Nombre de literaux dans le corps");
		label_nb_variables_existentielles = new JLabel("Nombre de variables existentielles");

		panel_labels = new JPanel();
		panel_labels.setLayout(new GridLayout(4,0));
		panel_labels.add(label_clause_de_horn);
		panel_labels.add(label_range_restricted);
		panel_labels.add(label_nb_literaux_corps);
		panel_labels.add(label_nb_variables_existentielles);

		check_clause_de_horn = new JCheckBox();
		check_range_restricted = new JCheckBox();
		check_nb_literaux_corps = new JCheckBox();
		check_nb_variables_existentielles = new JCheckBox();
		
		panel_checks = new JPanel();
		panel_checks.setLayout(new GridLayout(4,0));
		panel_checks.add(check_clause_de_horn);
		panel_checks.add(check_range_restricted);
		panel_checks.add(check_nb_literaux_corps);
		panel_checks.add(check_nb_variables_existentielles);

		spin_nb_literaux_corps = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
		spin_nb_variables_existentielles = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
		
		spin_nb_literaux_corps.setVisible(false);
		spin_nb_variables_existentielles.setVisible(false);
		
		panel_spins = new JPanel();
		panel_spins.setLayout(new GridLayout(4,0));
		panel_spins.add(new JLabel(""));
		panel_spins.add(new JLabel(""));
		panel_spins.add(spin_nb_literaux_corps);
		panel_spins.add(spin_nb_variables_existentielles);
		
		this.add(panel_labels);
		this.add(panel_checks);
		this.add(panel_spins);
	}

	private void ajouterListeners(){
		check_nb_literaux_corps.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent event) {
				spin_nb_literaux_corps.setVisible(check_nb_literaux_corps.isSelected());
			}
		});
		check_nb_variables_existentielles.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent event) {
				spin_nb_variables_existentielles.setVisible(check_nb_variables_existentielles.isSelected());
			}
		});
	}
	
	public void executer(){
		ClauseDeHorn.check = check_clause_de_horn.isSelected();
		RangeRestricted.check = check_range_restricted.isSelected();
		NombreDeLiterauxCorps.check = check_nb_literaux_corps.isSelected();
		if(check_nb_literaux_corps.isSelected()){
			NombreDeLiterauxCorps.valeur = Integer.parseInt(spin_nb_literaux_corps.getValue().toString());
		}
		NombreDeVariablesExistentielles.check = check_nb_variables_existentielles.isSelected();
		if(check_nb_variables_existentielles.isSelected()){
			NombreDeVariablesExistentielles.valeur = Integer.parseInt(spin_nb_variables_existentielles.getValue().toString());
		}
	}
}
